"use strict";
/**
 * osd 服务接口
 * @author niko
 * @deprecated 不再使用, 使用x-site-core-db中的osd服务
 */
exports.__esModule = true;
var lib_1 = require("@wanmi/x-site-core-osd/lib");
var co = require('co');
var osdClientInstance;
/**
 * osd服务对象，只提供put Object操作
 * @date   2015-09-11
 * @author niko
 * @param  {String}   accessKeyId     osd Id
 * @param  {String}   accessKeySecret osd 密钥
 * @param  {String}   keyPath         保存在osd的路径,e.g. /qianmicom/d2c/dev/:adminID/[pc|mobile]/
 */
var Client = /** @class */ (function () {
    function Client(osdConfig) {
        this.osd = lib_1.osdClient(osdConfig);
    }
    /**
     * 保存文件至osd
     * @date   2015-09-11
     * @author niko
     * @param  {String|Buffer|ReadStream}   src      filepath, new Buffer(), ReadStream
     * @param  {String}   adminID  商户id
     * @param  {String}   distName 存放的文件名字
     * @param  {Boolean}  isPC     是否PC端资源
     */
    Client.prototype.putObject = function (src, distName) {
        return co(this.osd.putObject(src, distName));
    };
    /**
     *
     * @param src
     * @param distName
     * @returns {*}
     */
    Client.prototype.putObjectAbsolute = function (src, absoluteDistName) {
        return co(this.osd.putObjectAbsolute(src, absoluteDistName));
    };
    /**
     * 返回值 是一个buffer 对象..
     * @param distName
     * @returns {*}
     */
    Client.prototype.getObject = function (distName) {
        return co(this.osd.getObject(distName));
    };
    Client.prototype.getObjectAbsolute = function (absoluteDistName) {
        return co(this.osd.getObjectAbsolute(absoluteDistName));
    };
    /**
     * 删除数据
     * @param distName
     * @returns {*}
     */
    Client.prototype.delObject = function (distName) {
        return co(this.osd.delObject(distName));
    };
    /**
     * Head an object and get the meta info.
     *
     *
     * @param distName
     * @returns {Promise<any>}
     */
    Client.prototype.head = function (distName) {
        return co(this.osd.head(distName));
    };
    Client.prototype.listObject = function (distDir) {
        return co(this.osd.listObject(distDir));
    };
    /**
     * 复制内容;;
     * @param name
     * @param sourceName
     * @param {{}} options
     * @returns {Promise<any>}
     */
    Client.prototype.copy = function (name, sourceName, options) {
        if (options === void 0) { options = {}; }
        return co(this.osd.copy(name, sourceName, options));
    };
    /**
     *
     * @param options :{prefix:absoluteDistDir,"max-keys":1000}
     *                或 "x-site/prod/d2cStore/A1078241/view/";
     * @return {*}
     */
    Client.prototype.listObjectAbsolute = function (absoluteDistDir) {
        return co(this.osd.listObjectAbsolute(absoluteDistDir));
    };
    /**
     * 批量删除
     * @param distNames
     * @returns {*}
     */
    Client.prototype.delMultiObjectAbsolute = function (distNames, options) {
        return co(this.osd.delMultiObjectAbsolute(distNames, options));
    };
    return Client;
}());
exports.Client = Client;
function getOsdClient(osdConfig) {
    if (osdClientInstance) {
        return osdClientInstance;
    }
    else if (osdConfig && osdConfig.accessKeyId && osdConfig.accessKeySecret) {
        return (osdClientInstance = new Client(osdConfig));
    }
    else {
        throw new Error('必须传入OSD配置文件');
    }
}
exports.getOsdClient = getOsdClient;
exports.getPrefix = function (osdConfig) {
    if (osdConfig && osdConfig.bucketName && osdConfig.endPoint) {
        var endPoint = exports.getEndPoint(osdConfig);
        var prefix = "https://" + endPoint;
        console.log(prefix);
        return prefix;
    }
    else {
        throw new Error('必须传入OSD配置文件');
    }
};
exports.getEndPoint = function (osdConfig) {
    if (osdConfig && osdConfig.bucketName && osdConfig.endPoint) {
        return osdConfig.bucketName + "." + osdConfig.endPoint;
    }
    else {
        throw new Error('必须传入OSD配置文件');
    }
};
